#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#include <stdio.h>
#include <unistd.h>
#include <memory.h>

void CloseSock( int aSockFd )
{
   close( aSockFd );
}

int StartSock( char * aHost, int aPort )
{
   int sSockFd  = -1;
   int sAddrLen = 0;
   int sRV      = 0;
   
   struct sockaddr_in sSvrAddr;
   
   sSockFd = socket( AF_INET, SOCK_STREAM, 0 );
   
   if ( sSockFd > 0 )
   {
      memset( &sSvrAddr, 0, sizeof( sSvrAddr ) );
      sSvrAddr.sin_family = AF_INET;
      sSvrAddr.sin_addr.s_addr = inet_addr( aHost );
      sSvrAddr.sin_port = htons( aPort );
      sAddrLen = sizeof( sSvrAddr );
      
      sRV = connect( sSockFd, (struct sockaddr *)&sSvrAddr, sAddrLen );
      
      if ( sRV < 0 )
      {
         close( sSockFd );
         sSockFd = -1;
      }
   }
   else
   {
      /* do nothing */
   }
   return sSockFd;
}
